﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public partial class Admin_Login : System.Web.UI.Page
{
    DataProvider duLieu = new DataProvider();
    ListBox listBox = new ListBox();

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            string UserName = Request.Form["username"];
            string Password = Request.Form["password"];

            if (!string.IsNullOrEmpty(UserName) & !string.IsNullOrEmpty(Password))
            {
                DataTable bangloginadmin = new DataTable();

                listBox.Items.Clear();
                duLieu.MakeDuLieu(listBox, UserName);

                bangloginadmin = duLieu.Load_Du_Lieu_Admin_New("select id,tendnqt,matkhauqt,hotenqt,chucdanh from quantri where tendnqt=?", listBox);
                if (bangloginadmin.Rows.Count != 0)
                {

                    if (Password == (string)bangloginadmin.Rows[0][2])
                    {
                        int id = (int)bangloginadmin.Rows[0][0];
                        Session["Username"] = (string)bangloginadmin.Rows[0][1];
                        Session["Logged"] = 2;
                        Response.Redirect("Default.aspx");
                    }
                    else
                    {
                        dangnhaperror.Text = "<font face='tahoma' size='2' color='red'>Đăng Nhập Không Thành Công</font>";
                        dangnhaperror.Visible = true;
                    }
                }
                else
                {
                    dangnhaperror.Text = "<font face='tahoma' size='2' color='red'>Đăng Nhập Không Thành Công</font>";
                    dangnhaperror.Visible = true;
                }
            }
        }
    }
}